#include <iostream>
#include <functional>
#include <map>
void print()
{
    std::cout << "helloworld" << std::endl;
}

class func
{
public:
    void operator()()
    {
        std::cout << "fuck" << std::endl;
    }
};
class Minus
{
public :
    int operator()(int a, int b)
    {
        return 0;
    }
};

int add(int a, int b)
{
    return a + b;
}

int divide(int a, int b, int c)
{

}
//map里面放函数指针
std::map<char,std::function<int(int,int)>> calculation;

int Calculate(char symbol, int a, int b)
{
    auto f = calculation[symbol];
    return f(a,b);
}
class Func
{
public:
    void print()
    {
        std::cout << "fuck" << std::endl;
    }
};

int main()
{
    std::function<void()> f = [](){std::cout << "lambda" << std::endl;};
    f();

    calculation['+'] = add;
    calculation['+'] = Minus();
    calculation['*'] = [](int a, int b){return a*b;};

    std::cout << Calculate('*', 1, 2) << std::endl;

    Func func;
    auto f = std::bind(&Func::print, &func);
    f();

    //函数绑定器
    //bind改变函数的调用方式
    
    //函数个数不匹配
    //std::placeholders::_1:占位符  函数原参继续占用该位置
    auto d = std::bind(divide, std::placeholders::_1,std::placeholders::_2,1);
    calculation['/'] = d;
    std::cout << Calculate('/',10,2) << std::endl;
    
    
    return 0;
}